#!/usr/bin/env bash
# Copyright (c) 2024 maminjie <canpool@163.com>
# SPDX-License-Identifier: MulanPSL-2.0

usage() {
    echo "usage: bash docker_clean.sh IMAGE_ID"
}

image_id="$1"

if [ $# -lt 1 ]; then
    usage; exit
fi

container_ids=$(docker ps -a | grep $image_id | awk '{print $1}')

for id in $container_ids; do
    docker stop $id && docker rm $id
done

docker rmi $image_id
